import request from '../../../utils/request'
import { IResponseBase } from '../../user/type'
import { IResponseTradeMark } from '../treademark/type'
import {
  IResponseBaseAttrList,
  IResponseSpuData,
  IResponseTrademarkImgList,
  ISkuDataResponse,
  ISkuParam,
  ISpuData,
} from './type'

export const reqSpuData = (page: number, limit: number, c3Id: string) =>
  request.get<any, IResponseSpuData>(
    `/admin/product/${page}/${limit}?category3Id=${c3Id}`,
  )

export const reqAllTrademark = () =>
  request.get<any, IResponseBase>(
    '/admin/product/baseTrademark/getTrademarkList',
  )

export const reqImage = (spuId: string) =>
  request.get<any, IResponseTrademarkImgList>(
    `/admin/product/spuImageList/${spuId}`,
  )

export const reqSpuHasAllAttr = (spuId: string) =>
  request.get(`/admin/product/spuSaleAttrList/${spuId}`)

export const reqSaleAttrList = () =>
  request.get<any, IResponseBaseAttrList>('/admin/product/baseSaleAttrList')

export const updateSpuForm = (param: ISpuData) => {
  if (param.id) {
    request.post('/admin/product/updateSpuInfo', param)
  } else {
    request.post('/admin/product/saveSpuInfo', param)
  }
}
export const addSku = (param: ISkuParam) => {
  return request.post<any, IResponseBase>('/admin/product/saveSkuInfo', param)
}
export const reqFindSkuInfo = (spuId: string) =>
  request.get<any, ISkuDataResponse>(`/admin/product/findBySpuId/${spuId}`)

export const reqDeleteSpu = (spuId: string) =>
  request.delete<any, IResponseBase>(`/admin/product/deleteSpu/${spuId}`)
